<template>
  <div class="counter-warp">
    <textarea v-model="ip" placeholder="示例：192.168.1.1,192.168.1.2"/>
    <span class="tips">提示：多个IP地址使用英文逗号" , "隔开</span>
    <a class="butclass" name="sure" @click="addip">确定添加</a>
   
   
   <mptoast />
  </div>
  
</template>

<script>
import { requestPost } from '@/utils/index'
import mptoast from 'mptoast'
export default {
  components: {
    mptoast
  },
  data () {
    return {
      ip: ''
    }
  },
  onLoad () {
    wx.setNavigationBarTitle({
      title: '添加 IP 白名单'
    })
  },
  methods: {
    addip () {
      var that = this
      var data = {
        'openid': wx.getStorageSync('openid'),
        'ip': this.ip
      }
      wx.showLoading({
        title: '添加IP',
        mask: true
      })
      console.log(data)
      requestPost(wx.getStorageSync('requestUrl') + '/wxsys/addIpWithOpenid', data, 'POST').then(function (value) {
        if (value.error_code === 0) {
          wx.showLoading({
            title: '添加成功',
            mask: true
          })
          that.ip = ''
        } else {
          wx.showLoading({
            title: value.msg,
            mask: true
          })
        }
        setTimeout(function () {
          wx.hideLoading()
        }, 1500)
      }, function (value) {
        wx.showLoading({
          title: value,
          mask: true
        })
        setTimeout(function () {
          wx.hideLoading()
        }, 1500)
      })
    }
  }
}
</script>

<style>
.tips{
  margin: 30px 20px auto;
  width: 90%;
  color: rgba(0, 0, 0, 0.500);
}
.counter-warp {
  margin-top: 2px;
}
textarea{
  border: 1px solid rgba(128, 128, 128, 0.322);
  margin: 30px auto;
  width: 90%;
  height: 200px;
}
.butclass{
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 24px;
  text-align: center;
  color: rgb(14, 14, 22);
  background-color: rgb(57,156,201);
  position: fixed;
  bottom: 0px;
}
</style>
